package com.dikang.yygh.user.api;


import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dikang.yygh.common.exception.YyghException;
import com.dikang.yygh.common.result.Result;
import com.dikang.yygh.common.result.ResultCodeEnum;
import com.dikang.yygh.common.utils.AuthContextHolder;
import com.dikang.yygh.model.user.UserInfo;
import com.dikang.yygh.user.service.UserInfoService;
import com.dikang.yygh.vo.user.LoginVo;
import com.dikang.yygh.vo.user.UserAuthVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author k3
 * @since 2021-08-26
 */
@RestController
@Api(tags = "用户登录接口")
@RequestMapping("/api/user")
public class UserInfoApiController {
    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation(value = "会员登录")
    @PostMapping("login")
    public Result login(@RequestBody LoginVo loginVo){
        Map<String, Object> login = userInfoService.login(loginVo);
        return Result.ok(login);
    }
    @PostMapping("auth/userAuth")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request){
        userInfoService.userAuth(AuthContextHolder.getUserId(request),userAuthVo);
        return Result.ok();
    }

    //获取用户
    @GetMapping("auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request){
        UserInfo userInfo = userInfoService.getById(AuthContextHolder.getUserId(request));
        return Result.ok(userInfo);
    }




}

